<template>
  <el-dialog
    :title="!dataForm.checkId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="用户id" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="用户id"></el-input>
    </el-form-item>
    <el-form-item label="用户手机号" prop="userTel">
      <el-input v-model="dataForm.userTel" placeholder="用户手机号"></el-input>
    </el-form-item>
    <el-form-item label="小区名称" prop="plot">
      <el-input v-model="dataForm.plot" placeholder="小区名称"></el-input>
    </el-form-item>
    <el-form-item label="地址" prop="address">
      <el-input v-model="dataForm.address" placeholder="地址"></el-input>
    </el-form-item>
    <el-form-item label="面积" prop="area">
      <el-input v-model="dataForm.area" placeholder="面积"></el-input>
    </el-form-item>
    <el-form-item label="房产证图片" prop="houseImages">
      <el-input v-model="dataForm.houseImages" placeholder="房产证图片"></el-input>
    </el-form-item>
    <el-form-item label="审核状态" prop="checkStatus">
      <el-input v-model="dataForm.checkStatus" placeholder="审核状态"></el-input>
    </el-form-item>
    <el-form-item label="发布状态" prop="publishStatus">
      <el-input v-model="dataForm.publishStatus" placeholder="发布状态"></el-input>
    </el-form-item>
    <el-form-item label="房子id" prop="houseId">
      <el-input v-model="dataForm.houseId" placeholder="房子id"></el-input>
    </el-form-item>
    <el-form-item label="求购id" prop="buyId">
      <el-input v-model="dataForm.buyId" placeholder="求购id"></el-input>
    </el-form-item>
    <el-form-item label="求租id" prop="rentId">
      <el-input v-model="dataForm.rentId" placeholder="求租id"></el-input>
    </el-form-item>
    <el-form-item label="订单号" prop="orderNum">
      <el-input v-model="dataForm.orderNum" placeholder="订单号"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          checkId: 0,
          userId: '',
          userTel: '',
          plot: '',
          address: '',
          area: '',
          houseImages: '',
          checkStatus: '',
          publishStatus: '',
          houseId: '',
          buyId: '',
          rentId: '',
          orderNum: ''
        },
        dataRule: {
          userId: [
            { required: true, message: '用户id不能为空', trigger: 'blur' }
          ],
          userTel: [
            { required: true, message: '用户手机号不能为空', trigger: 'blur' }
          ],
          plot: [
            { required: true, message: '小区名称不能为空', trigger: 'blur' }
          ],
          address: [
            { required: true, message: '地址不能为空', trigger: 'blur' }
          ],
          area: [
            { required: true, message: '面积不能为空', trigger: 'blur' }
          ],
          houseImages: [
            { required: true, message: '房产证图片不能为空', trigger: 'blur' }
          ],
          checkStatus: [
            { required: true, message: '审核状态不能为空', trigger: 'blur' }
          ],
          publishStatus: [
            { required: true, message: '发布状态不能为空', trigger: 'blur' }
          ],
          houseId: [
            { required: true, message: '房子id不能为空', trigger: 'blur' }
          ],
          buyId: [
            { required: true, message: '求购id不能为空', trigger: 'blur' }
          ],
          rentId: [
            { required: true, message: '求租id不能为空', trigger: 'blur' }
          ],
          orderNum: [
            { required: true, message: '订单号不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.checkId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.checkId) {
            this.$http({
              url: this.$http.adornUrl(`/system/systemcheck/info/${this.dataForm.checkId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userId = data.systemCheck.userId
                this.dataForm.userTel = data.systemCheck.userTel
                this.dataForm.plot = data.systemCheck.plot
                this.dataForm.address = data.systemCheck.address
                this.dataForm.area = data.systemCheck.area
                this.dataForm.houseImages = data.systemCheck.houseImages
                this.dataForm.checkStatus = data.systemCheck.checkStatus
                this.dataForm.publishStatus = data.systemCheck.publishStatus
                this.dataForm.houseId = data.systemCheck.houseId
                this.dataForm.buyId = data.systemCheck.buyId
                this.dataForm.rentId = data.systemCheck.rentId
                this.dataForm.orderNum = data.systemCheck.orderNum
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/system/systemcheck/${!this.dataForm.checkId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'checkId': this.dataForm.checkId || undefined,
                'userId': this.dataForm.userId,
                'userTel': this.dataForm.userTel,
                'plot': this.dataForm.plot,
                'address': this.dataForm.address,
                'area': this.dataForm.area,
                'houseImages': this.dataForm.houseImages,
                'checkStatus': this.dataForm.checkStatus,
                'publishStatus': this.dataForm.publishStatus,
                'houseId': this.dataForm.houseId,
                'buyId': this.dataForm.buyId,
                'rentId': this.dataForm.rentId,
                'orderNum': this.dataForm.orderNum
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
